package com.tanhua.app.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.tanhua.app.service.TanhuaService;
import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.pojo.Question;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 查询今日佳人信息
     * @return
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest(){
        //1.调用Service执行业务逻辑
        TodayBest todayBestVo = tanhuaService.todayBest();

        //2.返回结果
        return ResponseEntity.ok(todayBestVo);
    }


    /**
     * 分页查询推荐好友列表
     * @param recommendUserDto
     * @return
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto recommendUserDto){
        //1.调用Service执行业务逻辑
        PageResult pageResult = tanhuaService.recommendation(recommendUserDto);

        //2.返回结果
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 根据页面展示的佳人用户id查询佳人的信息
     * @return
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity findUserInfoById(@PathVariable("id")Long userId){
        //1.调用Service执行业务逻辑
       TodayBest bestUser = tanhuaService.findUserInfoById(userId);

        //2.返回结果
        return ResponseEntity.ok(bestUser);
    }


    /**
     * 查询佳人的陌生人问题
     * @param userId
     * @return
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity findUserQuestions(Long userId){
        //1.调用Service层执行业务逻辑
        String question = tanhuaService.findUserQuestions(userId);

        //2.返回结果
        return ResponseEntity.ok(question);
    }


    /**
     * 回复佳人的陌生人问题
     * @return
     * param.get("userid"):该参数是当前用户把消息回复给了谁
     * param.get("reply"):该参数当前用户回复的内容
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map param){
        //1.获取参数内容
        String id = param.get("userId").toString();
        Long toUserId = Long.valueOf(id);
        String reply = param.get("reply").toString();

        //2.调用Serivce层执行业务逻辑
        tanhuaService.replyQuestions(toUserId,reply);

        //3.返回结果
        return ResponseEntity.ok(null);
    }


    /**
     * 查询探花卡片列表数据
     * @return
     */
    @GetMapping("/cards")
    public ResponseEntity queryCardsList(){
        //1.通过Serivce执行业务逻辑
        List<TodayBest> todayBestsList = tanhuaService.queryCardsList();

        //2.返回结果
        return ResponseEntity.ok(todayBestsList);
    }




    /**
     * 探花列表右滑——喜欢操作
     * @return
     *  GET/tanhua/:id/love
     */
    @GetMapping("/{id}/love")
    public ResponseEntity likeUser(@PathVariable("id") Long likeUserId){
        tanhuaService.likeUser(likeUserId);

        return ResponseEntity.ok(null);
    }


    /**
     *探花列表左滑——不喜欢操作
     * @param likeUserId
     * @return
     * GET/tanhua/:id/unlove
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity notLikeUser(@PathVariable("id") Long likeUserId){
        tanhuaService.notLikeUser(likeUserId);
        return ResponseEntity.ok(null);
    }


    /**
     * 探花搜附近
     * @return
     */
    @GetMapping("/search")
    public ResponseEntity<List<NearUserVo>> queryNearUser(String gender, @RequestParam(defaultValue = "2000")String distance){
        //1.通过Service执行业务逻辑
        List<NearUserVo> list = tanhuaService.queryNearUser(gender,distance);
        //2.返回结果
        return ResponseEntity.ok(list);
    }
}
